﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Audit.Listener;
using NHibernate.Audit.Mapping;
using NHibernate.Cfg;
using NHibernate.Event;

namespace NHibernate.Audit.Cfg
{
    public class DefaultAuditConfiguration : AuditConfiguration 
    {

        public DefaultAuditConfiguration()
        {
            this.ClassConvention = new DefaultAuditClassConvention();
            this.TableConvention = new DefaultAuditTableConvention();
            this.RevisionConfiguration = new DefaultRevisionConfiguration();
            this.Listener = new AuditEventListener(this);
        }

        public void Configure(Configuration configuration)
        {
            var metaBuilder = new MetadataBuilder(configuration, this);
            metaBuilder.BuildMetadata();
            var auditMapper = new AuditMapper(new MappingsFacade(configuration), 
                new TableMapper());
            auditMapper.AddAuditing(metaBuilder.ClassMetadataCollection);


            configuration.SetListener(ListenerType.PreInsert, Listener);

        }



        

    }
}
